<script>
export default {
  methods: {
    // 获取openid
    getOpenid() {
      let data = {
        code: this.d.code
      }
      this.$http
        .request({
          method: 'GET',
          url: this.d.api.getOpenid,
          body: data
        })
        .then(
          rs => {
            console.log(rs)
            this.$store.commit('setOpenId', rs.d.openid)
            this.f.toPage('login')
          },
          err => {
            console.log(err)
          }
        )
    }
  },
  created() {
    // 更新时提示更新
    this.f.update()
    // 启动日志
    const logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)
    // 判断登录
    this.f.needLogin(this).then(
      rs => {
        this.d.code = rs.code
        console.log(rs.code, this.d.code)
        if (!this.$store.state.openid) {
          this.getOpenid()
        }
      },
      err => {
        // 已登录
        console.log('已登录', err)
      }
    )
  },
  onShow(argOption) {
    // argOption = this.$root.$mp.appargOptions
    console.log(argOption, this.d)
    this.d.shareTicket = ''
    // argOption.scene为场景值，可设置不同场景显示不周页面
    // 从群进入
    if (argOption && argOption.scene && argOption.scene === 1044) {
      if (argOption.shareTicket) {
        this.d.shareTicket = argOption.shareTicket
        wx.getShareInfo({
          shareTicket: argOption.shareTicket,
          success(rs) {
            console.log('分享加密信息:', rs)
          },
          fail(err) {
            console.log('err:', err)
          }
        })
      }
    }
    // 连接
    if (this.$store.state.openid) {
      // console.log('')
    }
  }
}
</script>

<style lang="scss">
@import './asset/css/index.scss';
@include oReset();
@include oRotate();
@include oFsSet();
@include oPdMgSet(8, 5);
@include oFlex();
.c-b {
  @include iCB();
}

.f-l {
  float: left;
}

.f-r {
  float: right;
}

.ta-c {
  text-align: center;
}

.ta-l {
  text-align: left;
}

.ta-r {
  text-align: right;
}
.i {
  font-size: 48px;
}
page {
  transition: width 2s;
}
// theme
.theme-c {
  color: $themeCol;
}

button[type='primary'] {
  @include iBtnBgColor($themeCol, 2);
}

.theme-bg {
  background-color: $themeCol;
  color: #fff;
}
.bg-f {
  background-color: $bgf;
}
.bd-grey {
  border: 1px solid #f5f5f5;
}
.full-h {
  height: 100vh;
}
</style>
